<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@page import="org.quickbundle.orgauth.IOrgauthConstants"%>
<%@page import="org.quickbundle.base.beans.factory.RmBeanFactory"%>
<%@page import="org.quickbundle.tools.helper.RmJspHelper"%>
<%@page import="org.quickbundle.tools.helper.RmPopulateHelper"%>
<%@page import="org.quickbundle.orgauth.rmparty.util.IRmPartyConstants"%>
<%@page import="org.quickbundle.orgauth.cache.RmPartyTypeCache"%>
<%@page
	import="org.quickbundle.orgauth.rmpartytype.util.IRmPartyTypeConstants"%>
<%@page
	import="org.quickbundle.orgauth.rmpartyrelation.util.IRmPartyRelationConstants"%>
<%@page import="com.dfhc.ISystemConstant"%>
<%@page import="com.dfhc.util.CryptoHelper"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/dfhc" prefix="dfhc"%>
<!-- 全局js 和css包 -->

<script type="text/javascript" src="<%=request.getContextPath()%>/js/rm-tools.js"></script>
<%@ include file="/jsp/include/web/new/global.jsp"%>
<title>Insert title here</title>
</head>
<body>
	<form name="form" method="post" id="form">
		<dfhc:table templateId="iframe_table_h_ui">
			<dfhc:tr>
				<dfhc:td >
					<dfhc:table templateId="iframe_table_h_ui">
						<dfhc:tr >
							<dfhc:td >
							<dfhc:div templateId="h_ui_div">
							本节点
							</dfhc:div></dfhc:td>
							<dfhc:td>
							<dfhc:div templateId="h_ui_div">
								${bean.child_party_name}(ID: ${bean.child_party_id})
							</dfhc:div>
							</dfhc:td>
						</dfhc:tr>
						<dfhc:tr>
							<dfhc:td >
							<dfhc:div templateId="h_ui_div">
							本关系
							</dfhc:div>
							</dfhc:td>
							<dfhc:td>
							<dfhc:div templateId="h_ui_div">
						父节点${bean.parent_party_name} (子编码:${bean.child_party_code} )
							</dfhc:div>
							</dfhc:td>
						</dfhc:tr>
						<dfhc:tr>
							<dfhc:td >
							<dfhc:div templateId="h_ui_div">
							名称
							</dfhc:div>
							</dfhc:td>
							<dfhc:td>
							<dfhc:div templateId="h_ui_div">
								<dfhc:input  name="this_party_name" value="${bean.child_party_name}" />
								<dfhc:button templateId="h_ui_updateThisPartyName_button" onclick="updateThisPartyName_onClick()" />
							</dfhc:div>
							</dfhc:td>
						</dfhc:tr>
						<dfhc:tr>
							<dfhc:td >
							<dfhc:div templateId="h_ui_div">
							排序值
							</dfhc:div>
							</dfhc:td>
							<dfhc:td>
							<dfhc:div templateId="h_ui_div">
								<dfhc:input  name="order_code" maxLength="100" value="" />
								<dfhc:button templateId="h_ui_updateOrderCode_button" onclick="updateOrderCode()" />
							</dfhc:div>
							</dfhc:td>
						</dfhc:tr>

						<dfhc:tr>
							<dfhc:td >
								<dfhc:span templateId="h_ui_not_null_span"></dfhc:span>团体类型:
							</dfhc:td>
							<dfhc:td>
							<select name="party_type_id" id="party_type_id" inputName="<%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("party_type_id")%>" validate="notNull;" >
							<option value="">请选择</option>
	    					<c:forEach items ="${rmPartyTypeVo}"  var = "li" >
							<option value="${li.id}"  id="${li.bs_keyword}"  >${li.name}</option>
							</c:forEach>
								</select>
							</dfhc:td>
						</dfhc:tr>
						<dfhc:tr>
							<dfhc:td >
								<dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("name")%></dfhc:td>
							<dfhc:td>
								<dfhc:input templateId="h_ui_input" name="name" value="" maxLength="100" validate="notNull;" />
							</dfhc:td>
						</dfhc:tr>
						<dfhc:extendField tableName="RM_PARTY" />						
						<dfhc:tr>
							<dfhc:td ><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("description")%></dfhc:td>
							<dfhc:td>
									<dfhc:textarea templateId="h_ui_textarea" cols="" rows=""   placeholder="说点什么...最少输入10个字符" maxlength="500" name="description"  />
							</dfhc:td>
						</dfhc:tr>
					</dfhc:table>
				</dfhc:td>
			</dfhc:tr>
			<dfhc:tr>
				<dfhc:td >
				<dfhc:div templateId="h_ui_div">
				<dfhc:button templateId="h_ui_insertChildNode_button" onclick="insertChildNode()" />
				<%-- <dfhc:button templateId="h_ui_relationChildNode_button" onclick="relationChildNode()" /> --%>
				<dfhc:button templateId="h_ui_deleteChildNode_button" onclick="deleteChildNode()" />
				<dfhc:button templateId="h_ui_deleteChildRelation_button" onclick="deleteChildRelation()" />
				</dfhc:div>
				<br>
				<dfhc:button templateId="h_ui_addViewRootNode_button" onclick="addViewRootNode()" />
				<%-- <dfhc:button templateId="h_ui_relateViewRootNode_button" onclick="relationViewRootNode()" /> --%>
				 </dfhc:td>
			</dfhc:tr>
		</dfhc:table>

		<dfhc:input type="hidden" name="view_id" id="view_id" value="${view_id }" />
		<input type="hidden" name="parent_party_id" id="parent_party_id" value="${bean.child_party_id }" />
		<dfhc:input type="hidden" name="parent_party_name" id="parent_party_name" value="${bean.child_party_name }" />
		<dfhc:input type="hidden" name="parent_party_code" id="parent_party_code" value="${bean.child_party_code }" />
		<dfhc:input type="hidden" name="child_party_id" id="child_party_id" value="" />
		<dfhc:input type="hidden" name="child_party_name" id="child_party_name" value="" />

		<dfhc:input type="hidden" name="is_inherit" value="1" />

		<dfhc:input type="hidden" name="cmdInput" value="" />

	</form>
</body>
</html>
<script type="text/javascript">
$(function(){
	
	var flag ="${empty bean}";
	if(flag == "true"){
		$('.showDiv').hide();
		
	}else if(flag == "false"){
		$('#party_type_id').val('${bean.child_party_type_id}');
		$('.showDiv').show();
	}
});
var ssurl = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab")%>';
function addViewRootNode() {
	if($("#party_type_id").val() == '<%=RmPartyTypeCache.getPartyType(IOrgauthConstants.OrgTree.USER.value()).getId()%>') {
		alert("请在“员工管理”节点中新增用户！");
		return false;
	}
	if($("input[name='name']").val() == "" || $("input[name='name']").val() == '' ){
		alert("名称 不能为空！");
		return false;
	}
	if($('#party_type_id').val() == null || $('#party_type_id').val() == ''){
		alert("机构类型不能为空！");
		return false;
	}
	var url = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?cmd=org&fbb=addViewRootNode';
	submitAjax(url,$("#form").serialize(),ssurl);
	$('#left_ifram_id').contentWindow.location.reload(true);
}
 function insertChildNode() {
	 var flag ="${empty bean}";
		//if(flag == "true"){
			
		//}else if(flag == "false"){
			//$('#party_type_id').val('${bean.child_party_type_id}');
		//}
    var party_type_id = $("#party_type_id option:selected").val();		
	if(party_type_id == '<%=RmPartyTypeCache.getPartyType(IOrgauthConstants.OrgTree.USER.value()).getId()%>') {
		alert("请在“员工管理”节点中新增用户！");
		return false;
	}
	if($("input[name='name']").val() == "" || $("input[name='name']").val() == '' ){
		alert("名称 不能为空！");
		return false;
	}
	var flag ;
	if(party_type_id == null || party_type_id == ''){
		alert("员工id 不能为空！");
		return false;
	}
	var url = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?cmd=org&fbb=insertChildNode';
	submitAjax(url,$("#form").serialize(),ssurl);
	$('#left_ifram_id').contentWindow.location.reload(true);
}

function relationChildNode() {
	if($('child_party_id').val() != "") {
		var url = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?cmd=org&fbb=relationChildNode&view_id=${view_id}';
		submitAjax(url,$("#form").serialize(),ssurl);
	}
}

function relationViewRootNode() {
	debugger;
	<%-- getReference(new Array($('child_party_id').val(),$('child_party_name').val()), '<%=request.getContextPath()%>/', '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?referenceInputType=radio'); --%>
	if($('child_party_id').val() != "") {
		var url ='<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?cmd=org&fbb=relationViewRootNode&view_id=${view_id}';
		submitAjax(url,$("#form").serialize(),ssurl);
	}
}
function updateThisPartyName_onClick() {
	if($('this_party_name').val() == '') {
		alert('名称不能为空');
		form.this_party_name.focus();
		return ;
	};
	if(!getConfirm()) {  //如果用户在确认对话框中点"取消"
		return false;
	}
	var url = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?cmd=org&fbb=updateThisPartyName';
	submitAjax(url,$("#form").serialize(),ssurl);
}
function updateOrderCode(){
	if(!getConfirm()) {
		return false;
		}
	var url = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/manageParty")%>?cmd=org&fbb=updateOrderCode';
	submitAjax(url,$("#form").serialize(),ssurl);
}
function deleteChildNode(){
	var url = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?cmd=org&fbb=deleteChildNode&parent_party_code=${bean.child_party_code}&view_id=${view_id}&parent_party_id=${bean.child_party_id}';
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: url,
			dataType: 'json',
			success: function(data){
				//更新随机码
				$("#_csrfcode_").val(data._csrfcode_);
				//$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				/* $('.table-sort').DataTable().ajax.reload(); */
				parent.location.reload();
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
	
}
function deleteChildRelation(){
	var url = '<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/manegePartyTab/managePartylist")%>?cmd=org&fbb=deleteChildRelation&parent_party_code=${bean.child_party_code}&view_id=${view_id}&parent_party_id=${bean.child_party_id}';
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: url,
			dataType: 'json',
			success: function(data){
				//更新随机码
				$("#_csrfcode_").val(data._csrfcode_);
				//$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				$('.table-sort').DataTable().ajax.reload();
				parent.location.reload();
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
<%if("1".equals(request.getParameter("refresh_parent"))) { %>
	parent.location.reload();
<%}%> 
</script>